﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace HuiLian.Cloud.Controls
{
    public class ImageButton:Button
    {
        public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(Geometry), typeof(ImageButton), new PropertyMetadata(null));

        /// <summary>
        /// 图标
        /// </summary>
        [Description("图标"), Category("")]
        public Geometry Image
        {
            get { return (Geometry)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }
        }

        public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register("ImageWidth", typeof(double), typeof(ImageButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标宽度
        /// </summary>
        public double ImageWidth
        {
            get { return (double)GetValue(ImageWidthProperty); }
            set { SetValue(ImageWidthProperty, value); }
        }

        public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register("ImageHeight", typeof(double), typeof(ImageButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标高度
        /// </summary>
        public double ImageHeight
        {
            get { return (double)GetValue(ImageHeightProperty); }
            set { SetValue(ImageHeightProperty, value); }
        }

        public static readonly DependencyProperty ImageColorProperty = DependencyProperty.Register("ImageColor", typeof(Brush),
            typeof(ImageButton), new PropertyMetadata(Brushes.Gray, OnPropertyChanged));

        /// <summary>
        /// 图片颜色
        /// </summary>
        public Brush ImageColor
        {
            set { SetValue(ImageColorProperty, value); }
            get { return (Brush)GetValue(ImageColorProperty); }
        }

        public static readonly DependencyProperty BorderColorProperty = DependencyProperty.Register("BorderColor", typeof(Brush),
            typeof(ImageButton), new PropertyMetadata(Brushes.Gray, OnPropertyChanged));

        /// <summary>
        /// 边框颜色
        /// </summary>
        public Brush BorderColor
        {
            set { SetValue(BorderColorProperty, value); }
            get { return (Brush)GetValue(BorderColorProperty); }
        }

        public static readonly DependencyProperty BorderCornerRadiusProperty = DependencyProperty.Register("BorderCornerRadius", typeof(CornerRadius),
            typeof(ImageButton), new PropertyMetadata(new CornerRadius(2), OnPropertyChanged));

        /// <summary>
        /// 按钮圆角
        /// </summary>
        public CornerRadius BorderCornerRadius
        {
            set { SetValue(BorderCornerRadiusProperty, value); }
            get { return (CornerRadius)GetValue(BorderCornerRadiusProperty); }
        }

        public static readonly DependencyProperty ButtonBackgroundProperty = DependencyProperty.Register("ButtonBackground", typeof(Brush),
        typeof(ImageButton), new PropertyMetadata(Brushes.White, OnPropertyChanged));

        /// <summary>
        /// 按钮背景颜色
        /// </summary>
        [Description("背景颜色"), Category("")]
        public Brush ButtonBackground
        {
            set { SetValue(ButtonBackgroundProperty, value); }
            get { return (Brush)GetValue(ButtonBackgroundProperty); }
        }

        private static void OnPropertyChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs args)
        {
            ImageButton button = dependency as ImageButton;
            if (args.Property.Name.Equals("ImageColor"))
                button.ImageColor = (Brush)args.NewValue;
            if (args.Property.Name.Equals("BorderColor"))
                button.BorderColor = (Brush)args.NewValue;
            if (args.Property.Name.Equals("ButtonBackground"))
                button.ButtonBackground = (Brush)args.NewValue;
        }
    }
}
